package in.iqing.model.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.lidroid.xutils.db.annotation.Column;
import com.lidroid.xutils.db.annotation.Finder;
import com.lidroid.xutils.db.annotation.Id;
import com.lidroid.xutils.db.annotation.NoAutoIncrement;
import com.lidroid.xutils.db.annotation.Table;
import com.lidroid.xutils.db.annotation.Transient;
import com.lidroid.xutils.db.sqlite.FinderLazyLoader;

import java.io.Serializable;
import java.util.List;

/**
 * Created by ZuoShu on 15/7/7.
 */
@Table(name = "book")
public class Book implements Serializable {
    @Id
    @NoAutoIncrement
    @Column(column = "id")
    @JSONField(name = "id")
    private int id;

    @Column(column = "url")
    @JSONField(name = "url")
    private String url;

    @Column(column = "intro")
    @JSONField(name = "intro")
    private String intro;

    @Column(column = "title")
    @JSONField(name = "title")
    private String title;

    @Column(column = "cover")
    @JSONField(name = "cover")
    private String cover;

    @Column(column = "views")
    @JSONField(name = "views")
    private int views;

    @Column(column = "updated_time")
    @JSONField(name = "updated_time")
    private long updatedTime;

    @Column(column = "created_time")
    @JSONField(name = "created_time")
    private long createTime;

    @Column(column = "author_name")
    @JSONField(name = "author_name")
    private String author;

    @Column(column = "status")
    @JSONField(name = "status")
    private int status;

    @Column(column = "press")
    @JSONField(name = "press")
    private String press;

    @Transient
    @JSONField(name = "uploaders")
    private List<User> uploaders;

    @Finder(valueColumn = "id", targetColumn = "book_id")
    @JSONField(name = "categories")
    private List<Category> categories;

    @Column(column = "end")
    @JSONField(name = "end")
    private boolean end;

    @Column(column = "type")
    @JSONField(name = "type")
    private int type;

    @Column(column = "last_volume_id")
    @JSONField(name = "last_volume_id")
    private int lastVolumeId;

    @Column(column = "last_chapter_id")
    @JSONField(name = "last_chapter_id")
    private int lastChapterId;

    @Column(column = "last_chapter_title")
    @JSONField(name = "last_chapter_title")
    private String lastChapterTitle;

    @Column(column = "last_volume_title")
    @JSONField(name = "last_volume_title")
    private String lastVolumeTitle;

    @Column(column = "chapter_count")
    @JSONField(name = "chapter_count")
    private int chapterCount;

    @Column(column = "volume_count")
    @JSONField(name = "volume_count")
    private int volumeCount;

    @Column(column = "subscribe")
    private boolean subscribe;

    @Column(column = "cached_chapter_count")
    private int cachedChapterCount;

    @Transient
    @Finder(valueColumn = "id", targetColumn = "book_id")
    private FinderLazyLoader<Volume> volumes; // 关联对象多时建议使用这种方式，延迟加载效率较高。

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public int getViews() {
        return views;
    }

    public void setViews(int views) {
        this.views = views;
    }

    public long getUpdatedTime() {
        return updatedTime;
    }

    public void setUpdatedTime(long updatedTime) {
        this.updatedTime = updatedTime;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getPress() {
        return press;
    }

    public void setPress(String press) {
        this.press = press;
    }

    public List<User> getUploaders() {
        return uploaders;
    }

    public void setUploaders(List<User> uploaders) {
        this.uploaders = uploaders;
    }

    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

    public boolean isEnd() {
        return end;
    }

    public void setEnd(boolean end) {
        this.end = end;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getLastVolumeId() {
        return lastVolumeId;
    }

    public void setLastVolumeId(int lastVolumeId) {
        this.lastVolumeId = lastVolumeId;
    }

    public int getLastChapterId() {
        return lastChapterId;
    }

    public void setLastChapterId(int lastChapterId) {
        this.lastChapterId = lastChapterId;
    }

    public String getLastChapterTitle() {
        return lastChapterTitle;
    }

    public void setLastChapterTitle(String lastChapterTitle) {
        this.lastChapterTitle = lastChapterTitle;
    }

    public String getLastVolumeTitle() {
        return lastVolumeTitle;
    }

    public void setLastVolumeTitle(String lastVolumeTitle) {
        this.lastVolumeTitle = lastVolumeTitle;
    }

    public int getChapterCount() {
        return chapterCount;
    }

    public void setChapterCount(int chapterCount) {
        this.chapterCount = chapterCount;
    }

    public int getVolumeCount() {
        return volumeCount;
    }

    public void setVolumeCount(int volumeCount) {
        this.volumeCount = volumeCount;
    }

    public boolean isSubscribe() {
        return subscribe;
    }

    public void setSubscribe(boolean subscribe) {
        this.subscribe = subscribe;
    }

    public FinderLazyLoader<Volume> getVolumes() {
        return volumes;
    }

    public void setVolumes(FinderLazyLoader<Volume> volumes) {
        this.volumes = volumes;
    }

    public int getCachedChapterCount() {
        return cachedChapterCount;
    }

    public void setCachedChapterCount(int cachedChapterCount) {
        this.cachedChapterCount = cachedChapterCount;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Book qingBook = (Book) o;

        if (id != qingBook.id) return false;
        return !(url != null ? !url.equals(qingBook.url) : qingBook.url != null);

    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (url != null ? url.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", url='" + url + '\'' +
                ", intro='" + intro + '\'' +
                ", title='" + title + '\'' +
                ", cover='" + cover + '\'' +
                ", views=" + views +
                ", updatedTime=" + updatedTime +
                ", createTime=" + createTime +
                ", author='" + author + '\'' +
                ", status=" + status +
                ", press='" + press + '\'' +
                ", uploaders=" + uploaders +
                ", categories=" + categories +
                ", end=" + end +
                ", type=" + type +
                ", lastVolumeId=" + lastVolumeId +
                ", lastChapterId=" + lastChapterId +
                ", lastChapterTitle='" + lastChapterTitle + '\'' +
                ", lastVolumeTitle='" + lastVolumeTitle + '\'' +
                ", chapterCount=" + chapterCount +
                ", volumeCount=" + volumeCount +
                ", subscribe=" + subscribe +
                '}';
    }
}
